package dominion;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import dominion.controller.GameState;
import dominion.model.Card;
import dominion.model.Player;
import dominion.model.actions.base.Adventurer;
import dominion.model.actions.base.Bureaucrat;
import dominion.model.actions.base.Cellar;
import dominion.model.actions.base.Chancellor;
import dominion.model.actions.base.Chapel;
import dominion.model.actions.base.CouncilRoom;
import dominion.model.actions.base.Feast;
import dominion.model.actions.base.Festival;
import dominion.model.actions.base.Laboratory;
import dominion.model.actions.base.Library;
import dominion.model.actions.base.Market;
import dominion.model.actions.base.Militia;
import dominion.model.actions.base.Mine;
import dominion.model.actions.base.Moat;
import dominion.model.actions.base.Moneylender;
import dominion.model.actions.base.Remodel;
import dominion.model.actions.base.Smithy;
import dominion.model.actions.base.Spy;
import dominion.model.actions.base.Thief;
import dominion.model.actions.base.ThroneRoom;
import dominion.model.actions.base.Village;
import dominion.model.actions.base.Witch;
import dominion.model.actions.base.Woodcutter;
import dominion.model.actions.base.Workshop;
import dominion.model.points.Gardens;
import dominion.utils.Constants;

public class DominionDriver {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		GameState game = new GameState();
		List<Card> allCards = new ArrayList<Card>();
		allCards.add(new Adventurer());
		allCards.add(new Bureaucrat());
		allCards.add(new Cellar());
		allCards.add(new Chancellor());
		allCards.add(new Chapel());
		allCards.add(new CouncilRoom());
		allCards.add(new Feast());
		allCards.add(new Festival());
		allCards.add(new Gardens());
		allCards.add(new Laboratory());
		allCards.add(new Library());
		allCards.add(new Market());
		allCards.add(new Militia());
		allCards.add(new Mine());
		allCards.add(new Moat());
		allCards.add(new Moneylender());
		allCards.add(new Remodel());
		allCards.add(new Smithy());
		allCards.add(new Spy());
		allCards.add(new Thief());
		allCards.add(new ThroneRoom());
		allCards.add(new Village());
		allCards.add(new Witch());
		allCards.add(new Woodcutter());
		allCards.add(new Workshop());

		List<Integer> index = new ArrayList<Integer>();
		Random ran = new Random();
		for (int i = 0; i < 10; i++)
		{
			while (true)
			{
				Integer next = ran.nextInt(25);
				if (!index.contains(next))
				{
					index.add(next);
					break;
				}
			}
		}

		ArrayList<Card> cards = new ArrayList<Card>();
		for (Integer i : index)
		{
			cards.add(allCards.get(i));
		}

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Constants.printer.print("Enter number of players:");
		int numOfPlayers = Integer.parseInt(in.readLine().trim());
		if (numOfPlayers < 2 || numOfPlayers > 4)
		{
			Constants.printer.print("The game is for 2 - 4 players.");
			System.exit(1);
		}

		List<Player> players = new ArrayList<Player>();
		for (int i = 0; i < numOfPlayers; i++)
		{
			Constants.printer.print("Enter player " + (i + 1) + "'s name: ");
			Player current = new Player(in.readLine());
			players.add(current);
		}

		game.initGame(cards, players);
		game.startGame();
	}

}
